% -*- mode: latex -*-
% -*- coding: latin-1 -*-

\documentclass[final]{beamer}
\usetheme{Singapore}
%% \usetheme{JuanLesPins}

\usepackage{color}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{multirow}
\usepackage[hang,small,bf]{caption}

\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps}
\usepackage{amsmath,amssymb}

\setbeamercovered{transparent}

\usefonttheme{default}
\usecolortheme{seagull}


\lstset{
language=python,
basicstyle=\ttfamily\tiny\setstretch{1},
stringstyle=\color{red},
showstringspaces=false,
alsoletter={1234567890},
otherkeywords={\ , \}, \{},
keywordstyle=\color{blue},
emph={access,and,break,class,continue,def,del,elif ,else,%
except,exec,finally,for,from,global,if,import,in,i s,%
lambda,not,or,pass,print,raise,return,try,while},
emphstyle=\color{gray}\bfseries,
emph={[2]True, False, None, self},
emphstyle=[2]\color{green},
emph={[3]from, import, as},
emphstyle=[3]\color{red},
upquote=true,
morecomment=[s]{"""}{"""},
commentstyle=\color{gray}\slshape,
emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
emphstyle=[4]\color{blue},
literate=*{:}{{\textcolor{blue}:}}{1}%
{=}{{\textcolor{gray}=}}{1}%
{-}{{\textcolor{gray}-}}{1}%
{+}{{\textcolor{gray}+}}{1}%
{*}{{\textcolor{gray}*}}{1}%
{!}{{\textcolor{gray}!}}{1}%
{(}{{\textcolor{gray}(}}{1}%
{)}{{\textcolor{gray})}}{1}%
{[}{{\textcolor{gray}[}}{1}%
{]}{{\textcolor{gray}]}}{1}%
{<}{{\textcolor{gray}<}}{1}%
{>}{{\textcolor{gray}>}}{1},%
framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{gray},#1
}

\title{Intimate Testing - (or, Why I Stopped Banging My Head Against the Wall And Started Caring)}
\author{Sidnei da Silva}
\institute{Enfold Systems, Inc.}

\pgfdeclareimage[width=5cm,height=1.5cm]{enfold-logo}{bg-slide}
\logo{\pgfuseimage{enfold-logo}}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:

% \beamerdefaultoverlayspecification{<+->}

\begin{document}

  \begin{frame}
    \titlepage
  \end{frame}

  \section{Introduction}

  \subsection{What?}

  \begin{frame}
    \frametitle{Apples and Oranges}

    \begin{itemize}
      \item Software != Mathematics
      \item You can't prove that Software is correct!
      \item But you can assert that it conforms to certain expectations.
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{Analogy: Letter Of Intent}

    \begin{quote}
    a document outlining an agreement between two or more parties before the agreement is finalized
    \end{quote}

    \begin{itemize}
      \item to clarify the key points of a complex transaction for the
        convenience of the parties
      \item to declare officially that the parties are currently
        negotiating, as in a merger or joint venture proposal
      \item to provide safeguards in case a deal collapses during
        negotiation
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{Non-obvious observation}

    \begin{quote}
      A primary purpose for testing is to detect software failures so
      that defects may be uncovered and corrected. This is a
      non-trivial pursuit. Testing cannot establish that a product
      functions properly under all conditions but can only establish
      that it does not function properly under specific conditions.
    \end{quote}

  \end{frame}

  \begin{frame}
    \frametitle{Conclusion 1}

    \begin{quote}
      Testing that your Software matches provided specifications and
      expectations is important. Testing that it does not do what it
      is not supposed to is equally or more important.
    \end{quote}

  \end{frame}

  \section{Reasoning}

  \subsection{Why?}

  \begin{frame}
    \frametitle{For Whom the Bell Tolls}

    \begin{quote}
      A related theme is the vivid sense of camaraderie in the face of
      death and the surrendering of one's self for the common cause
      and the good of the people.
    \end{quote}

    \begin{itemize}
      \item writing tests is commonly perceived as costly
      \item and it is: quality tests can easily exceed the size and
        scope of software itself
      \item upfront sacrifice pays on: backwards compatibility and
        refactoring
      \item a safety net for yourself and for others
      \item knowledge calcified, memory doesn't last forever (also,
        the bus factor)
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{The Real Cost of (non-)Testing}

    \begin{quote}
      Software Errors Cost U.S. Economy \$59.5 Billion Annually
    \end{quote}

    \begin{table}
      {\tiny
      \begin{tabular}{|c|c|c|c|c|c|c|}
        \hline
        \multicolumn{2}{|c|}{} & \multicolumn{5}{|c|}{Detected} \\
        \hline
        \multicolumn{2}{|c|}{} & Requirements & Architecture & Construction & System Test & Post-Release \\ \hline
        \multirow{3}{*}{Introduced} & Requirements & 1x & 3x & 5-10x & 10x & 10-100x \\
        & Architecture & - & 1x & 10x & 15x & 25-100x \\
        & Construction & - & - & 1x & 10x & 10x-25x \\
        \hline
      \end{tabular}
      \caption{Cost of fixing a bug relative to Time Introduced vs. Time Detected}
      }
    \end{table}

  \end{frame}

  \begin{frame}
    \frametitle{Side-effects of Good Testing}

    \begin{itemize}
      \item writing tests for software you do not know is great way
        to learn about how the software works
      \item writing tests refines the APIs
      \item playing by the rules: backwards compatibility
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{Conclusion 2}

    \begin{quote}
      Testing is a long-term investment that largely pays for
      itself. Designing Software with testing in mind not only makes
      your Software more flexible, but also more refined and robust.
    \end{quote}

  \end{frame}

  \section{Practical and Intimate}

  \subsection{How?}

  \begin{frame}
    \frametitle{The basics}

    \begin{itemize}
    \item unstructured (assert/if-else)
    \item testing library == organization
    \item testing framework
    \item ``mocking''
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{unittest}

    \lstinputlisting[language=Python]{unittest1.py}

  \end{frame}

  \begin{frame}
    \frametitle{mocker 1}

    \lstinputlisting[language=Python]{mocker1.py}

  \end{frame}

  \begin{frame}
    \frametitle{mocker 2}

    \lstinputlisting[language=Python]{mocker2.py}

  \end{frame}

  \begin{frame}
    \frametitle{``The works''}

    \begin{itemize}
    \item tests as documentation
    \item integration
    \item functional
    \item load testing
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{doctest 1}

    \lstinputlisting[language=Python]{doctest1.py}

  \end{frame}


  \begin{frame}
    \frametitle{doctest 2}

    \lstinputlisting[language=Python]{doctest2.txt}
    \lstinputlisting[language=Python]{doctest2.py}

  \end{frame}

  \begin{frame}
    \frametitle{doctest 2 output}

    \lstinputlisting[language=Python]{doctest2.output}

  \end{frame}

  \begin{frame}
    \frametitle{zope.testbrowser}

    \lstinputlisting[language=Python]{testbrowser1.txt}

  \end{frame}

  \begin{frame}
    \frametitle{The ``cherry on top''}

    \begin{itemize}
    \item fuzzy testing
    \item coverage testing
    \item regression testing
    \end{itemize}

  \end{frame}

  \begin{frame}
    \frametitle{Available tooling}

    \begin{itemize}
    \item ``unittest''
    \item ``doctest''
    \item ``mocker''
    \item {Zope,CMF,Plone}TestCase - integration
    \item ``zope.testbrowser'' - functional
    \item ``zope.testing.testrunner'' - coverage
    \item JMeter/FunkLoad (YES!)
    \end{itemize}

  \end{frame}

  \section{Auf Wiedersehen!}
  \subsection{Ciao!}

  \begin{frame}
    \frametitle{Questions?}

    \begin{itemize}
    \item Any questions?
    \end{itemize}

  \end{frame}

  \section{References}
  \subsection{Always helpful}

  \begin{frame}
    \frametitle{Some Useful Links}

    \begin{itemize}
    \item \url{http://googletesting.blogspot.com/}
    \item \url{http://agiletesting.blogspot.com/}
    \item \url{http://labix.org/mocker}
    \item \url{http://plone.org/documentation/tutorial/testing/functional-tests}
    \item \url{http://funkload.nuxeo.com/}
    \end{itemize}

  \end{frame}

\end{document}
